// Package service /*docker相关
package service

import (
	"strings"

	cf "godocker/common/functions"
)

type docker struct {
	SName string

	fileDir string
}

func dockerNew() *docker {
	return &docker{
		"docker",
		installDir + "common/dockerfile",
	}
}

func (d docker) install() {
	d.setEnvFile()
	d.setYmlFile()
}

func (d docker) setEnvFile() {
	str := cf.GetDockerfile(".env")
	str = strings.Replace(str, "{volumeDir}", installDir, -1)
	str = strings.Replace(str, "{app-name}", appName, -1)
	cf.WriteToFileTrunc(installDir+"/.env", str)
}

func (d docker) setYmlFile() {
	str := cf.GetDockerfile("docker-compose.yml")
	network := cf.GetEnvVal(installDir+"/.env", "network=")

	oldNetWork := "$network"
	newNetWork := network
	newStr := strings.Replace(str, oldNetWork, newNetWork, -1)

	cf.WriteToFileTrunc(installDir+"/docker-compose.yml", newStr)
}
